#include <stdio.h>
#include <iostream>

/*
 * 识别纯虚函	P125
 */
class Base
{
	public:
		virtual void demo(void) = 0;
};

class Derived:public Base
{
	public:
		virtual void demo(void)
		{
			printf("DERIVER.\n");
		}
};

int main()
{
    Base *p = new Derived;

    printf("%d %d\n", sizeof(class Base), sizeof(class Derived));	// 4  4

    p->demo();

    return 0;
}

/*
	DERIVER.
 */

#if 0

1.纯虚类也有构造函数

/*
 * intel
 */
00000000000011a9 <main>:
    11a9:	f3 0f 1e fa          	endbr64 
    11ad:	55                   	push   %rbp
    11ae:	48 89 e5             	mov    %rsp,%rbp
    11b1:	53                   	push   %rbx
    11b2:	48 83 ec 18          	sub    $0x18,%rsp	// rsp-=0x18
    11b6:	bf 08 00 00 00       	mov    $0x8,%edi	// edi=0x8
    11bb:	e8 d0 fe ff ff       	callq  1090 <_Znwm@plt>	// new(8)
    11c0:	48 89 c3             	mov    %rax,%rbx	// rbx=rax=this
    11c3:	48 89 df             	mov    %rbx,%rdi	// rdi=rbx=this
    11c6:	e8 c7 00 00 00       	callq  1292 <_ZN7DerivedC1Ev>	// Derived(rdi)
    11cb:	48 89 5d e8          	mov    %rbx,-0x18(%rbp)		// rbp-0x18=rbx=this
    11cf:	48 8b 45 e8          	mov    -0x18(%rbp),%rax		// rax=rbp-0x18
    11d3:	48 8b 00             	mov    (%rax),%rax		// rax=(this)
    11d6:	48 8b 10             	mov    (%rax),%rdx		// rdx=((this))
    11d9:	48 8b 45 e8          	mov    -0x18(%rbp),%rax		// rax=rbp-0x18=this
    11dd:	48 89 c7             	mov    %rax,%rdi		// rdi=rax=this
    11e0:	ff d2                	callq  *%rdx			// rdx(rdi)
    11e2:	b8 00 00 00 00       	mov    $0x0,%eax		// eax=0
    11e7:	48 83 c4 18          	add    $0x18,%rsp		// rsp+=0x18
    11eb:	5b                   	pop    %rbx
    11ec:	5d                   	pop    %rbp
    11ed:	c3                   	retq   

0000000000001254 <_ZN7Derived4demoEv>:
    1254:	f3 0f 1e fa          	endbr64 
    1258:	55                   	push   %rbp
    1259:	48 89 e5             	mov    %rsp,%rbp		// rbp=rsp
    125c:	48 83 ec 10          	sub    $0x10,%rsp		// rsp-=0x10
    1260:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)		// rbp-0x8=rdi=this
    1264:	48 8d 3d 9a 0d 00 00 	lea    0xd9a(%rip),%rdi        # 2005 <_ZStL19piecewise_construct+0x1>
    126b:	e8 40 fe ff ff       	callq  10b0 <puts@plt>		// puts(rdi)
    1270:	90                   	nop
    1271:	c9                   	leaveq 
    1272:	c3                   	retq   
    1273:	90                   	nop

0000000000001274 <_ZN4BaseC1Ev>:
    1274:	f3 0f 1e fa          	endbr64 
    1278:	55                   	push   %rbp
    1279:	48 89 e5             	mov    %rsp,%rbp
    127c:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)		// rbp-0x8=rdi=this
    1280:	48 8d 15 e1 2a 00 00 	lea    0x2ae1(%rip),%rdx        # 3d68 <__cxa_pure_virtual@CXXABI_1.3> // rdx=rip+0x2ae1
    1287:	48 8b 45 f8          	mov    -0x8(%rbp),%rax		// rax=rbp-0x8
    128b:	48 89 10             	mov    %rdx,(%rax)		// (rax)=(this)=rip+0x2ae1
    128e:	90                   	nop
    128f:	5d                   	pop    %rbp
    1290:	c3                   	retq   
    1291:	90                   	nop

0000000000001292 <_ZN7DerivedC1Ev>:
    1292:	f3 0f 1e fa          	endbr64 
    1296:	55                   	push   %rbp
    1297:	48 89 e5             	mov    %rsp,%rbp
    129a:	48 83 ec 10          	sub    $0x10,%rsp		// rsp-=0x10
    129e:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)		// rbp-0x8=rdi=this
    12a2:	48 8b 45 f8          	mov    -0x8(%rbp),%rax		// rax=this
    12a6:	48 89 c7             	mov    %rax,%rdi		// rdi=this
    12a9:	e8 c6 ff ff ff       	callq  1274 <_ZN4BaseC1Ev>	// Base(rdi)
    12ae:	48 8d 15 9b 2a 00 00 	lea    0x2a9b(%rip),%rdx        # 3d50 <_ZTV7Derived+0x10> // rdx=rip+0x2a9b
    12b5:	48 8b 45 f8          	mov    -0x8(%rbp),%rax		// rax=rbp-0x8=this
    12b9:	48 89 10             	mov    %rdx,(%rax)		// (rax)=(this)=rdx
    12bc:	90                   	nop
    12bd:	c9                   	leaveq 
    12be:	c3                   	retq   
    12bf:	90                   	nop

/*
 * arm
 */
00000000004008ec <main>:
  4008ec:	a9bd7bfd 	stp	x29, x30, [sp, #-48]!
  4008f0:	910003fd 	mov	x29, sp
  4008f4:	f9000bf3 	str	x19, [sp, #16]			// sp+16=x19
  4008f8:	d2800100 	mov	x0, #0x8                   	// #8
  4008fc:	97ffffb9 	bl	4007e0 <_Znwm@plt>		// new(8)
  400900:	aa0003f3 	mov	x19, x0				// x19=x0=return value = this
  400904:	aa1303e0 	mov	x0, x19				// x0=x19=this
  400908:	9400003c 	bl	4009f8 <_ZN7DerivedC1Ev>	// Derived(x0)
  40090c:	f90017b3 	str	x19, [x29, #40]			// x29+40=x19=this
  400910:	f94017a0 	ldr	x0, [x29, #40]			// x0=this
  400914:	f9400000 	ldr	x0, [x0]			// x0=(this)
  400918:	f9400001 	ldr	x1, [x0]			// x1=((this))
  40091c:	f94017a0 	ldr	x0, [x29, #40]			// x0=this
  400920:	d63f0020 	blr	x1				// ((this))(x0)
  400924:	52800000 	mov	w0, #0x0                   	// #0
  400928:	f9400bf3 	ldr	x19, [sp, #16]			// x19=sp+16
  40092c:	a8c37bfd 	ldp	x29, x30, [sp], #48
  400930:	d65f03c0 	ret

00000000004009b0 <_ZN7Derived4demoEv>:
  4009b0:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4009b4:	910003fd 	mov	x29, sp
  4009b8:	f9000fa0 	str	x0, [x29, #24]			// x29+24=x0=this
  4009bc:	90000000 	adrp	x0, 400000 <_init-0x720>	// x0=400000
  4009c0:	912b8000 	add	x0, x0, #0xae0			// x0=400ae0
  4009c4:	97ffff83 	bl	4007d0 <puts@plt>		// puts(x0)
  4009c8:	d503201f 	nop
  4009cc:	a8c27bfd 	ldp	x29, x30, [sp], #32
  4009d0:	d65f03c0 	ret

00000000004009d4 <_ZN4BaseC1Ev>:
  4009d4:	d10043ff 	sub	sp, sp, #0x10
  4009d8:	f90007e0 	str	x0, [sp, #8]			// sp+8=x0=this
  4009dc:	90000000 	adrp	x0, 400000 <_init-0x720>	// x0=400000
  4009e0:	912c6001 	add	x1, x0, #0xb18			// x1=400b18
  4009e4:	f94007e0 	ldr	x0, [sp, #8]			// x0=sp+8=this
  4009e8:	f9000001 	str	x1, [x0]			// (this)=400b18
  4009ec:	d503201f 	nop
  4009f0:	910043ff 	add	sp, sp, #0x10
  4009f4:	d65f03c0 	ret

00000000004009f8 <_ZN7DerivedC1Ev>:
  4009f8:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4009fc:	910003fd 	mov	x29, sp
  400a00:	f9000fa0 	str	x0, [x29, #24]			// x29+24=x0=this
  400a04:	f9400fa0 	ldr	x0, [x29, #24]			// x0=x29+24=this
  400a08:	97fffff3 	bl	4009d4 <_ZN4BaseC1Ev>		// Base(this)
  400a0c:	90000000 	adrp	x0, 400000 <_init-0x720>	// x0=400000
  400a10:	912c0001 	add	x1, x0, #0xb00			// x1=400b00
  400a14:	f9400fa0 	ldr	x0, [x29, #24]			// x0=x29+24=this
  400a18:	f9000001 	str	x1, [x0]			// (this)=400b00
  400a1c:	d503201f 	nop
  400a20:	a8c27bfd 	ldp	x29, x30, [sp], #32
  400a24:	d65f03c0 	ret

#endif
